package com.wangkang.educms.controller;
import com.wangkang.educms.entity.CrmBanner;
import com.wangkang.educms.service.CrmBannerService;
import com.wangkang.commonutils.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@Api(tags = "Banner后台管理")
@RequestMapping("/educms/crmAdmin")
//@CrossOrigin
public class BannerAdminController {
    @Autowired
    private  CrmBannerService crmBannerService;

    public BannerAdminController(CrmBannerService crmBannerService) {
        this.crmBannerService = crmBannerService;
    }

    @GetMapping("/pageBanner/{page}/{size}")
    @ApiOperation("分页查询Banner")
    public R pageBanner(@PathVariable("page") Integer page, @PathVariable("size") Long size){
        Page<CrmBanner> pageBanner = new Page<>(page, size);
        crmBannerService.page(pageBanner, null);
        return R.ok().data("item",pageBanner.getRecords()).data("total",pageBanner.getTotal());
    }

    @ApiOperation("添加Banner")
    @PostMapping("/addBanner")
    public R addBanner(@RequestBody CrmBanner crmBanner){
        crmBannerService.save(crmBanner);
        return R.ok();
    }

    @ApiOperation("修改Banner")
    @PutMapping("/updateBanner")
    public R updateBanner(@RequestBody CrmBanner crmBanner){
        crmBannerService.updateById(crmBanner);
        return R.ok();
    }

    @ApiOperation("删除Banner")
    @DeleteMapping("/remove/{id}")
    public R removeBanner(@PathVariable String id){
        crmBannerService.removeById(id);
        return R.ok();
    }

}